
#include <stdio.h>
#include <linux/videodev2.h>

#include "cbb_encoder_convert.h"
#include "cbb_enc_type.h"
#include "mpp_frame.h"
#include "rk_type.h"



hd_s32_t CbbConvertEncoderFormat(hd_u32_t in_format)
{
    //!V4L2格式转换为MPP库定义的格式表,后续根据需要进行扩展
    struct {
        int v4l2_format;
        int mpp_format;
    } convertList[] = {
        {V4L2_PIX_FMT_NV12, MPP_FMT_YUV420SP},
        {V4L2_PIX_FMT_NV16, MPP_FMT_YUV422SP},
        {V4L2_PIX_FMT_NV21, MPP_FMT_YUV420SP_VU},
        {V4L2_PIX_FMT_NV61, MPP_FMT_YUV422SP_VU},
        {V4L2_PIX_FMT_YUYV, MPP_FMT_YUV422_YUYV},
        {V4L2_PIX_FMT_YVYU, MPP_FMT_YUV422_YVYU},
        {V4L2_PIX_FMT_UYVY, MPP_FMT_YUV422_UYVY},
        {V4L2_PIX_FMT_VYUY, MPP_FMT_YUV422_VYUY},
    };

    for(int i=0;i<CBB_ARRLEN(convertList);i++){
        if(in_format == convertList[i].v4l2_format){
            return convertList[i].mpp_format;
        }
    }
    printf("unsupport convert type:%d\r\n", in_format);
    
    return CBB_CAMERA_ACK_ERROR;
}

hd_s32_t CbbConvertEncoderType(hd_u32_t in_type)
{
    //!cbb定义的编码类型转成MPP定义的编码类型表,后续根据需要进行扩展
    struct {
        int cbb_type;
        int mpp_type;
    } convertList[] = {
        {CBB_CAMERA_FMT_H264, MPP_VIDEO_CodingAVC},
        {CBB_CAMERA_FMT_JPEG, MPP_VIDEO_CodingMJPEG},
    };

    for(int i=0;i<CBB_ARRLEN(convertList);i++){
        if(in_type == convertList[i].cbb_type){
            return convertList[i].mpp_type;
        }
    }
    printf("unsupport convert type:%d\r\n", in_type);

    return CBB_CAMERA_ACK_ERROR;
}